package capstoneproject.dudiachi.Main;

import java.util.ArrayList;

import capstoneproject.dudiachi.Model.NavDrawerItem;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NavDrawerListAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<NavDrawerItem> navDrawerItems;
	public NavDrawerListAdapter(Context context, ArrayList<NavDrawerItem> navDrawerItems) {
		this.context = context;
		this.navDrawerItems = navDrawerItems;
	}
	
	@Override
	public int getCount() {
		return navDrawerItems.size();
	}

	@Override
	public Object getItem(int position) {
		return navDrawerItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if(row == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.drawer_list_item, null);
		}
		
		ImageView drawerIcon = (ImageView) row.findViewById(R.id.icon);
		TextView drawerTitle = (TextView) row.findViewById(R.id.title);
		
		drawerIcon.setImageResource(navDrawerItems.get(position).getIcon());
		drawerTitle.setText(navDrawerItems.get(position).getTitle());
		return row;
	}

}
